#include<bits/stdc++.h>
using namespace std;

struct Tree{
    const static int N = 500050;
    struct edge{
        int to, nxt;
    }e[N << 1];
    int head[N], lg[N], depth[N], father[N][22];
    int n, len, root, query_num;

    Tree(){n = 0; len = 0; memset(head, 0, sizeof(head)); }

    void add_edge(int u, int v){
        e[++len].to = v; e[len].nxt = head[u]; head[u] = len; return ;
    }

    void insert_edge(int u, int v){
        add_edge(u, v); add_edge(v, u);
    }

    void init_lg(){
        lg[0] = 0;
        for(int i = 1; i < N; i++)
            lg[i] = lg[i - 1] + (1 << lg[i - 1] == i);
        return ;
    }

    void dfs(int cur, int fath){
        int i;
        depth[cur] = depth[fath] + 1;
        father[cur][0] = fath;
        for(i = 1; (1 << i) <= depth[cur]; i++)
            father[cur][i] = father[father[cur][i - 1]][i - 1];
        for(int i = head[cur]; i; i = e[i].nxt){
            int to = e[i].to;
            if(to != fath) dfs(to, cur);
        }
        return ;
    }

    int lca(int x, int y){
        if(depth[x] < depth[y]) swap(x, y);
        while(depth[x] > depth[y]) x = father[x][lg[depth[x] - depth[y]] - 1];
        if(x == y) return x;
        for(int k = lg[depth[x]] - 1; k >= 0; k--){
            if(father[x][k] != father[y][k]){
                x = father[x][k];
                y = father[y][k];
            }
        }
        return father[x][0];
    }

    void lca_query(){
        init_lg();
        for(int j = 0; (1 << j) <= n; ++j){
            for(int i = 1; i <= n; i++) father[i][j] = -1; 
        }
        depth[0] = 0;		    
        dfs(root, 0);
        for(int i = 1; i <= query_num; i++){
            int x, y;
            scanf("%d%d", &x, &y);
            printf("%d\n", lca(x, y));
        }
        return ;
    }

}tree;

void init(){
    scanf("%d%d%d", &tree.n, &tree.query_num, &tree.root);
    for(int i = 1; i < tree.n; i++){
        int u, v;
        scanf("%d%d", &u, &v);
        tree.insert_edge(u, v);
    }
    return ;
}

void solve(){
    tree.lca_query();
    return ;
}

int main(){
    init();
    solve();
}